package com.kaifamiao.month04.day21;

import java.util.*;

public class Demo {

    public static void main(String[] args) {
//        Set<String> stringSet = new HashSet<>();
//        stringSet.add("123");
//        System.out.println(stringSet);

//        HashMap<Integer,StringBuffer> map = new HashMap<>();
//        map.put(1, new StringBuffer("abc"));
//        map.put(2, new StringBuffer("bcd"));
//        map.put(3, new StringBuffer("cde"));
//        map.put(4, new StringBuffer("def"));
//        map.put(5, new StringBuffer("efg"));
//        System.out.println(map);

//        Comparator<Person> comparator = (person1, person2) -> person1.getAge() - person2.getAge();

        TreeSet<Person> set = new TreeSet<>((person1, person2) -> person1.getAge() - person2.getAge());
        Person p1 = new Person("张三", 21);
        Person p2 = new Person("李四", 22);
        Person p3 = new Person("王五", 20);
        Person p4 = new Person("孙六", 19);
        set.add(p1);
        set.add(p2);
        set.add(p3);
        set.add(p4);
        System.out.println(set);
    }


}

class Person {
    String name;
    int age;

    public int getAge() {
        return age;
    }

    public void setAge(int age) {
        this.age = age;
    }

    public Person(String name, int age) {
        this.name = name;
        this.age = age;
    }

    @Override
    public String toString() {
        return "Person{" +
                "name='" + name + '\'' +
                ", age=" + age +
                '}';
    }
}
class PersonComparator implements Comparator<Person> {
    @Override
    public int compare(Person p1, Person p2) {
        return p1.age - p2.age;
    }
}
